import request from '@/utils/request';
import { transformCurUserInfo } from '@/utils';

export async function query() {
    return request('/api/users');
}

/**
 * 获取当前登录人职位信息
 */
export async function queryUserInfo() {
    return request('/api/uc/org/employee/v1/info/get', {
        method: 'POST'
    }).then(result => {
        // transformCurUserInfo 中提取了部分变量到根对象, 是为了方便开发, 但是触发的位置是在 login 中, 导致切换公司后, 旧值没有被更新导致问题
        if (result.code === 10000 || result.code === 20012 || result.code === 20013) {
            const newResult = { ...result };
            newResult.data = transformCurUserInfo(newResult.data);
            return newResult;
        }
        return result;
    });
}

export async function queryNotices() {
    return request('/api/notices');
}

/**
 * 用户中心-修改密码
 * @method Post
 * @param {string} confirmNewPassword 确认新密码
 * @param {string} newPassword 新密码
 * @param {string} password 旧密码
 */

export async function editPassword(params) {
    return request('/api/user/v2/account/edit', {
        method: 'POST',
        data: params
    });
}

// 忘记密码重置
export async function resetPassword(params) {
    return request('/api/user/public/v1/account/oa/forget', {
        method: 'POST',
        data: params
    });
}

export async function checkUserEmail(params) {
    // return request('/api/oa/v1/user/checkemployeenameemail', {
    return request('/api/uc/public/org/user/v1/checkemployeenameemail', {
        method: 'POST',
        data: params
    });
}

export async function getVerificationCode(params) {
    return request('/api/user/public/v1/verification/send', {
        method: 'POST',
        data: params
    });
}

/**
 * 更新员工头像
 * @method Post
 * @param {string} areaCode 电话区号:对应接口updatemobilebyuserId时必传
 * @param {integer} id 员工id:涉及到员工头像接口时必传
 * @param {string} mobile 手机号码:对应接口updatemobilebyuserId时必传
 * @param {integer} orgUserId 用户表主键ID:对应接口updatemobilebyuserId时必传
 * @param {object} resourceRelation 文件list
 *
 */
export async function updateemployeeavatar(params) {
    // return request('/api/oa/v1/user/updateuseravatar', {
    return request('/api/uc/org/user/v1/uploadEmployeeAvatar', {
        method: 'POST',
        data: params
    });
}
/**
 * 上传个人头像
 */
export async function uploademployeeavatar(params) {
    // return request('/api/oa/v1/user/uploaduseravatar', {
    return request('/api/uc/org/user/v1/updateEmployeeAvatar', {
        method: 'POST',
        data: params
    });
}
/**
 * 修改手机号码和区号
 */
export async function updatemobilebyuserId(params) {
    return request('/api/oa/v1/user/updatemobilebyuserId', {
        method: 'POST',
        data: params
    });
}

export async function getbusinesscard(params) {
    return request('/api/uc/org/employee/v1/queryBusinessCard', {
        method: 'POST',
        data: params,
        encryption: false
    });
}
export async function getHeartBeat() {
    return request('/api/oa/v1/test/heartbeat', {
        method: 'GET',
        encryption: false
    });
}
export async function getEmployeeinfo(params) {
    // return request('/api/oa/v1/employee/getemployeeinfo', {
    // return request('/api/uc/org/employee/v1/getEmployeePersonalInfo', {
    return request('/api/uc/org/employee/v1/getEmployeePersonalInfoNotPermission', {
        method: 'POST',
        data: params
    });
}
/**
 * 查看上级部门领导信息
 * @param {*} params 不需要传参
 */
export async function getILeader(params) {
    return request('/api/uc/org/employee/v1/getUpleaderInfo', {
        method: 'POST',
        data: params
    });
}

// export async function getEmployeeinfo(params) {
//     return request(
//         `/api/oa/v1/employee/getemployeeinfo?employeeId=${params.employeeId}`,
//         {
//             method: 'GET'
//         }
//     );
// }

/**
 * 接口优化-个人用户头像优化
 * @param {*} params 不需要传参
 */
export async function getPersonalPortrait() {
    // 组织架构改版
    // return request('/api/oa/v1/employee/getuseravatar', {
    return request('/api/uc/org/employee/v1/getEmployeeAvatar', {
        method: 'GET'
    });
}

/**
 * 首次登陆表单提交
 * @param userName
 */
export async function saveorupdate(param) {
    return request('/api/oa/v1/employee/usersaveorupdate', {
        method: 'POST',
        data: param
    });
}

export async function getEntryUserByUserCode({ userCode }) {
    return request(`/api/oa/v1/employee/getentryuserbyusercode/${userCode}`, {
        method: 'GET'
    });
}

export async function parseUserResume({ talentFileName }) {
    return request('/api/oa/v1/talent/talentComment', {
        method: 'GET',
        params: { talentFileName }
    });
}

export async function getUserResume({ userCode }) {
    return request('/api/oa/v1/talent/gettalentfilename', {
        method: 'GET',
        params: { userCode }
    });
}

/**
 * 获取完善员工信息邀请
 */
export async function getInformation(params) {
    return request('/api/oa/employee/msg/perfect/archives/push', {
        method: 'POST',
        data: params
    });
}

/**
 * 批量禁用/解禁员工
 * @param param 0 禁用 1启用
 */
export async function updateUserStatus(param) {
    return request('/api/uc/org/employee/v1/updateEmployeeStatus', {
        method: 'POST',
        data: param
    });
}
/**
 * 重置密码
 * @param {string} loginName 登录账号
 * @param {string} name 用户名称
 * @param {string} organizeType 组织类型 1：OA 2:商户
 */

export async function accountForget({ loginName, name, organizeType }) {
    return request('/api/user/v1/account/reset', {
        method: 'POST',
        data: { loginName, name, organizeType }
    });
}
/**
 * 导出员工个人档案所有信息
 * @param {string} userCode 用户code
 */
export async function getEmployeeexport({ employeeCode }) {
    return request(`/api/oa/v2/employeeInfoExport/info/${employeeCode}`, {
        method: 'POST',
        getResponse: true,
        encryption: false,
        isFile: true,
        responseType: 'blob',
        headers: { 'Content-Type': 'application/json' }
    });
}
/**
 * 导出员工个人档案所有信息
 * @param {string} userCode 用户code
 */
export async function updateUserInfo(param) {
    return request('/api/uc/org/employee/v1/updateRankAndDuty', {
        method: 'POST',
        data: param
    });
}

/**
 * 查询机构信息
 * @param {string} organizationCode 用户organizationCode
 */
export async function getOrganizationinfo(param) {
    return request('/api/org/v1/functional/get', {
        method: 'POST',
        data: param
    });
}

// 获取录用offer信息
export async function getRecruitmentInfo(data) {
    return request(`/api/recruitment/v1/employ/offer/${data.employId}`, {
        method: 'POST',
        data
    });
}
// 获取录用offer信息(加密id)
export async function getRecruitmentInfoByEncryptId(data) {
    return request(`/api/recruitment/v1/employ/offer/encry/${data.employId}`, {
        method: 'POST',
        data
    });
}

// 接受录用：employState 7；拒绝录用：employState 8
export async function acceptRecruitment(data) {
    return request(`/api/recruitment/public/v1/employ/actions/update_employ_status/${data.employId}`, {
        method: 'PUT',
        data
    });
}
// 接受录用，拒绝录用(加密id)
export async function acceptRecruitmentByEncryptId(data) {
    return request(`/api/recruitment/v1/employ/actions/update_employ_status/encry/${data.employId}`, {
        method: 'PUT',
        data
    });
}

/**
 * 查询员工入职材料
 * @param {string} employeeCode 员工编号
 */
export async function queryEmployeeEntryResource({ employeeCode }) {
    return request(`/api/uc/org/employee/v1/queryEmployeeEntryResource/${employeeCode}`, {
        method: 'GET'
    });
}

/**
 * 获取欢迎信状态
 */
export async function queryWelcomeLetterFlag() {
    return request('/api/oa/self/flag/v1/querySelfEmployeeFlag', {
        method: 'POST'
    });
}

/**
 * 更新欢迎信状态
 */
export async function updateWelcomeLetterFlag() {
    return request('/api/oa/self/flag/v1/readWelcomeLetter', {
        method: 'POST'
    });
}
